package com.zl.tby.vo;

import com.zl.tby.core.base.util.ToolsUtil;
import com.zl.tby.model.TbyWeather;
import lombok.Data;
import org.noear.solon.validation.annotation.NotNull;

import java.math.BigDecimal;

/**
 * 天气
 * @author changpeng
 * @version 1.0
 * @since 2024/9/21 7:28
 */
@Data
public class TbyWeatherForm {
    /**主键id*/
    private Long id;
    /**日期*/
    @NotNull(message = "不能为空")
    private String weatherDateFormat;
    /**天气*/
    private String weather;
    /**高温*/
    private BigDecimal highTemperature;
    /**低温*/
    private BigDecimal lowTemperature;
    /**平均气温*/
    private BigDecimal agvTemperature;
    /**降水量*/
    private BigDecimal precipitation;
    /**风速*/
    private BigDecimal windSpeed;
    /**风力*/
    private Integer windPower;
    /**风向*/
    private String windDirection;
    /**aqi*/
    private String aqi;
    /**湿度*/
    private BigDecimal humidity;
    /**紫外线等级(1:弱 2：较弱 3：中等 4：较强 5强)*/
    private Integer ultravioletRays;
    /**是否存在*/
    private Boolean exist;

    public TbyWeather createEntity() {
        TbyWeather entity = new TbyWeather();
        entity.setId(this.getId());
        entity.setWeather(this.getWeather());
        entity.setWeatherDate(ToolsUtil.dateString2Util(this.getWeatherDateFormat() + " 00:00:00", "yyyy-MM-dd HH:mm:ss"));
        entity.setHighTemperature(this.getHighTemperature());
        entity.setLowTemperature(this.getLowTemperature());
        entity.setAgvTemperature(this.getAgvTemperature());
        entity.setPrecipitation(this.getPrecipitation());
        entity.setWindSpeed(this.getWindSpeed());
        entity.setWindDirection(this.getWindDirection());
        entity.setAqi(this.getAqi());
        entity.setHumidity(this.getHumidity());
        entity.setUltravioletRays(this.getUltravioletRays());
        entity.setWindPower(this.getWindPower());
        return entity;
    }

    public void updateEntity(TbyWeather entity) {
        entity.setId(this.getId());
        entity.setWeather(this.getWeather());
        entity.setWeatherDate(ToolsUtil.dateString2Util(this.getWeatherDateFormat() + " 00:00:00", "yyyy-MM-dd HH:mm:ss"));
        entity.setHighTemperature(this.getHighTemperature());
        entity.setLowTemperature(this.getLowTemperature());
        entity.setAgvTemperature(this.getAgvTemperature());
        entity.setPrecipitation(this.getPrecipitation());
        entity.setWindSpeed(this.getWindSpeed());
        entity.setWindDirection(this.getWindDirection());
        entity.setAqi(this.getAqi());
        entity.setHumidity(this.getHumidity());
        entity.setUltravioletRays(this.getUltravioletRays());
        entity.setWindPower(this.getWindPower());
    }

    public static TbyWeatherForm convert(TbyWeather entity) {
        TbyWeatherForm form = new TbyWeatherForm();
        form.setId(entity.getId());
        form.setWeather(entity.getWeather());
        form.setWeatherDateFormat(ToolsUtil.dateUtil2String(entity.getWeatherDate(), "yyyy-MM-dd"));
        form.setHighTemperature(entity.getHighTemperature());
        form.setLowTemperature(entity.getLowTemperature());
        form.setAgvTemperature(entity.getAgvTemperature());
        form.setPrecipitation(entity.getPrecipitation());
        form.setWindSpeed(entity.getWindSpeed());
        form.setWindDirection(entity.getWindDirection());
        form.setAqi(entity.getAqi());
        form.setHumidity(entity.getHumidity());
        form.setUltravioletRays(entity.getUltravioletRays());
        form.setExist(true);
        form.setWindPower(entity.getWindPower());
        return form;
    }
}
